<template>
  <div class="mine-container">
    <div class="user-info-section">
      <div class="user-avatar">
        <img src="../assets/avatar_default.png" />
      </div>
      <div class="user-name">{{ userInfo.username}}</div>
    </div>
    <div class="order-section">
      <div class="section-header">
        <span class="section-title">我的订单</span>
        <span class="section-more">全部订单 ></span>
      </div>
      <div class="order-status">
        <div class="status-item">
          <van-icon name="balance-pay" size="24" />
          <span>待付款</span>
        </div>
        <div class="status-item">
          <van-icon name="logistics" size="24" />
          <span>待发货</span>
        </div>
        <div class="status-item">
          <van-icon name="send-gift-o" size="24" />
          <span>待收货</span>
        </div>
        <div class="status-item">
          <van-icon name="checked" size="24" />
          <span>已完成</span>
        </div>
      </div>
    </div>
    <div class="coupon-section">
      <div class="section-header">
        <span class="section-title">我的优惠券</span>
        <span class="section-more">全部优惠券 ></span>
      </div>
      <div class="coupon-status">
        <div class="status-item">
          <van-icon name="coupon-o" size="24" />
          <span>待使用</span>
        </div>
        <div class="status-item">
          <van-icon name="coupon-o" size="24" />
          <span>已使用</span>
        </div>
        <div class="status-item">
          <van-icon name="coupon-o" size="24" />
          <span>已过期</span>
        </div>
      </div>
    </div>

    <div class="function-section">
      <div class="function-item">
        <div class="item-left">
          <van-icon name="star-o" size="20" />
          <span>我的收藏</span>
        </div>
        <van-icon name="arrow" size="16" />
      </div>
      <div class="function-item"  @click="gotoaddress()">
        <div class="item-left">
          <van-icon name="location-o" size="20" />
          <span>收货地址</span>
        </div>
        <van-icon name="arrow" size="16" />
      </div>
      <div class="function-item">
        <div class="item-left">
          <van-icon name="service-o" size="20" />
          <span>服务中心</span>
        </div>
        <van-icon name="arrow" size="16" />
      </div>
    </div>

    <div class="logout-section">
      <van-button round block type="default" @click="handleLogout">退出登录</van-button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

const userInfo = ref({
  username: userStore.username
})
const handleLogout = () => {
    userStore.clearUser()
    router.push('/login')
}
const gotoaddress=()=>{
  router.push('/address')
}
</script>

<style scoped>
.mine-container {
  min-width: 78vh;
  padding: 15px;
  background-color: #F2F2F2;
  min-height: 100vh;
}

.user-info-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  background-image: url('../assets/user_head_bg.png');
  border-radius: 10px;
  margin-bottom: 15px;
}

.user-avatar img {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  margin-bottom: 10px;
}

.user-name {
  font-size: 16px;
  font-weight: bold;
  color: white;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  background-color: #fff;
  border-bottom: 1px solid #f5f5f5;
}

.section-title {
  font-size: 15px;
  font-weight: bold;
}

.section-more {
  font-size: 13px;
  color: #999;
}
.order-section, .coupon-section {
  background-color: #fff;
  border-radius: 10px;
  margin-bottom: 15px;
}

.order-status, .coupon-status {
  display: flex;
  padding: 15px 0;
}

.status-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.status-item span {
  font-size: 12px;
  margin-top: 8px;
}

.function-section {
  background-color: #fff;
  border-radius: 10px;
  margin-bottom: 15px;
}

.function-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid #f5f5f5;
}

.function-item:last-child {
  border-bottom: none;
}

.item-left {
  display: flex;
  align-items: center;
}

.item-left span {
  margin-left: 10px;
  font-size: 14px;
}

.logout-section {
  padding: 0 15px;
}

.logout-section .van-button {
  color: #ff4444;
  border-color: #ff4444;
}
</style>